﻿Public Class frm_backup
    Private bus As knm2012BUS
    Dim testbk As Integer = 0
    Dim testpatch As Integer = 0
    Dim time As Integer = 0

    Private Sub frm_backup_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Interval = 1000
        Timer1.Stop()
    End Sub
    Private Sub btnpatch_Click(sender As System.Object, e As System.EventArgs) Handles btnpatch.Click
        Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
        Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()
        If dlgResult = Windows.Forms.DialogResult.OK Then
            txtpatch.Text = MyFolderBrowser.SelectedPath
        End If
    End Sub
    Private Sub Testtextbox()
        If (Trim(txtfilename.Text) = "" Or Trim(txtpatch.Text) = "") Then
            MsgBox("Bạn phải nhập tên file sao lưu và đường dẫn, vui lòng kiểm tra lại", MsgBoxStyle.Exclamation, "Thông báo")
            testbk = 0
        Else
            testbk = 1
        End If
    End Sub
    Private Sub TestPatchSave()
        If (txtpatch.Text = "C:\") Then
            MsgBox("Vui lòng lựa chọn thư mục để lưu file backup", MsgBoxStyle.Exclamation, "Thông báo")
            testpatch = 0
        Else
            testpatch = 1
        End If
    End Sub
    Private Sub btnbackup_Click(sender As System.Object, e As System.EventArgs) Handles btnbackup.Click
        TestPatchSave()
        Testtextbox()
        If (testbk = 1 And testpatch = 1) Then
            Timer1.Start()
        End If
    End Sub
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        time = time + 1
        ProgressBarControl1.EditValue = ProgressBarControl1.EditValue + 50
        If time = 2 Then
            Timer1.Stop()
            BackUp()
        End If
    End Sub
    Private Sub BackUp()
        If (time = 2) Then
            Timer1.Stop()
            Timer1.Enabled = False
            Dim filename As String = txtfilename.Text
            Dim patch As String = txtpatch.Text
            bus = New knm2012BUS
            bus.Backup(filename, patch)
            MsgBox("Sao lưu dữ liệu thành công!", MsgBoxStyle.Information, "Thông báo")
        End If
    End Sub

    Private Sub btnclose_Click(sender As System.Object, e As System.EventArgs) Handles btnclose.Click
        Me.Close()
    End Sub

End Class